﻿// Based on Prism (https://github.com/PrismLibrary/Prism)
// Original Copyright (c) .NET Foundation
// Licensed under the MIT License

using Aliphant.Mvvm.XEvent.Events.Base.SubScription;

namespace Aliphant.Mvvm.XEvent.Events.Base
{
    public class PubSubEvent<T> : EventBase
    {
        public virtual void Publish(T payload)
        {
            if (payload == null) return;
            OnPublish(payload);
        }

        public virtual SubScriptionToken Subscribe(Action<T> action, Predicate<T> filter)
        {
            ISubScriptionToken subScriptionToken = new EventSubScriptionToken<T>(action, filter);
            return OnSubscribe(subScriptionToken);
        }
    }
}
